package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.domain.DestinationEs;
import cn.wolfcode.wolf2w.business.repository.DestinationEsRepository;
import cn.wolfcode.wolf2w.business.service.IDestinationEsService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.destination.RemoteDestinationService;
import cn.wolfcode.wolf2w.destination.entity.TaDestination;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DestinationEsServiceImpl implements IDestinationEsService {
    @Autowired
    private RemoteDestinationService remoteDestinationService;

    @Autowired
    private DestinationEsRepository destinationEsRepository;


    @Override
    public void initDestinationEs() {
        R<List<TaDestination>> r = remoteDestinationService.list(SecurityConstants.INNER);
        List<DestinationEs> destinationEsList = new ArrayList<>();
        List<TaDestination> destinationList = r.getData();
        for (TaDestination destination : destinationList) {
            DestinationEs destinationEs = new DestinationEs();
            BeanUtils.copyProperties(destination, destinationEs);
            destinationEsList.add(destinationEs);
        }
        System.err.println(destinationEsList);
        destinationEsRepository.saveAll(destinationEsList);
    }
}
